﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Tong;
public partial class MYCX_news : System.Web.UI.Page
{
    /// <summary>
    /// 数据操作通用类 实例 TextData
    /// </summary> 
    public TongUse TextData = new TongUse();

    /// <summary>
    /// 系统安装绝对路径
    /// </summary>
    public string Abs_Path = TongUse.SysPath;

    /// <summary>
    /// 用户存放数据的临时表
    /// </summary>
    DataTable MyDt = new DataTable();

    DataTable NewDt = new DataTable();

    public string str = "";

    public Tong.ThisSiteUse.SiteTong TextThisSite = new Tong.ThisSiteUse.SiteTong();
    protected void Page_Load(object sender, EventArgs e)
    {
        
        Button2.Attributes.Add("onclick", "window.open('../../inc/UpFile.aspx?formname=aspnetForm&amp;editname=" + CX_NEWS_Class_Pic.ClientID.ToString() + "&amp;uppath=UpFile','','status=no,scrollbars=no,top=20,left=110,width=600,height=265')");
        //帮字数据
        if (!IsPostBack)
        {
            BindData();
        }
        else
        {
            str = "    var ajax=new AJAXRequest();ajax.post('CX_News_Write_Itemp.ashx?id='+Id,'t=" + CX_NEWS_Class_Itemplitate_Address.ClientID + "&p=" + CX_NEWS_Class_Itemplitate_Parame.ClientID + "&d=" + CX_NEWS_Class_Directory.ClientID + "',function(obj) { eval(obj.responseText); });";

        }

        CX_Column_id.Attributes.Add("onchange", "CXgetVlaues(this.value);");//使用ajaxpro动态改变值



    }



    /// <summary>
    /// 保存数据
    /// </summary>
    void PageSave()
    {
        string sql = "";
        try
        {
            int.Parse(CX_Column_id.Text.Trim());
        }
        catch
        {
            tt.Text = "输入排序不能转换";
            Response.End();
        }
        if (CX_NEWS_Class_Name.Text.Trim() != "" && CX_NEWS_Class_Itemplitate_Address.Text.Trim() != "" && CX_NEWS_Class_Itemplitate_Parame.Text.Trim() != ""&&CX_NEWS_Class_Directory.Text.Trim()!="")
        {

            sql = "insert into [CX_NEWS_Class] ( CX_NEWS_Class_Name,CX_Column_id,  CX_NEWS_Class_Explier,   CX_NEWS_Class_Itemplitate_Address,  CX_NEWS_Class_Itemplitate_Parame,  CX_NEWS_Class_Pic,  CX_NEWS_Class_CreateFielfront,CX_NEWS_Class_Directory)";
            sql = sql + "values(";
            sql = sql + " '" + CX_NEWS_Class_Name.Text.Trim() + "'," + CX_Column_id.SelectedValue.Trim() + ",'" + CX_NEWS_Class_Explier.Text.Trim() + "', '" + CX_NEWS_Class_Itemplitate_Address.Text.Trim() + "','" + CX_NEWS_Class_Itemplitate_Parame.Text.Trim() + "', '" + CX_NEWS_Class_Pic.Text.Trim() + "', '" + CX_NEWS_Class_CreateFielfront.Text.Trim() + "','" + CX_NEWS_Class_Directory.Text.Trim().Replace("'", "") + "')";
            TextData.SqlDataSave(sql);//保存数据
            //Response.Write(sql);
            tt.Text = "添加新闻设定 " + CX_NEWS_Class_Name.Text.Trim() + " 成功";
            CX_NEWS_Class_Name.Text = "";
            CX_NEWS_Class_CreateFielfront.Text = "";

           // BindData();
        }
        else
        {
            tt.Text = "输入的信息内容不正确";
        }
    }

    /// <summary>
    /// ajax模式
    /// </summary>
    /// <param name="Sid"></param>
    /// <returns></returns>
    public String Chenge(string Sid)
    {
        
        if (Sid != "")
        {
            MyDt = TextData.SqlataSet("select top 1 * from [CX_Column] where CX_Column_id = " + Sid).Tables[0];
            CX_NEWS_Class_Itemplitate_Address.Text = MyDt.Rows[0]["CX_Column_ItemTemplate_Url"].ToString();//item
            CX_NEWS_Class_Itemplitate_Parame.Text = MyDt.Rows[0]["CX_Column_ItemTeplate_Parame"].ToString();//parme
            CX_NEWS_Class_Directory.Text = MyDt.Rows[0]["CX_Column_Directory"].ToString();//栏目目录
            //MyDt.Clear();
            str = "    var ajax=new AJAXRequest();ajax.post('CX_News_Write_Itemp.ashx?id='+Id,'t=" + CX_NEWS_Class_Itemplitate_Address.ClientID + "&p=" + CX_NEWS_Class_Itemplitate_Parame.ClientID + "&d=" + CX_NEWS_Class_Directory.ClientID + "',function(obj) { eval(obj.responseText); });";
        }
        return str;
    }


    void BindData()
    {
        try
        {
            NewDt.Columns.Add("东东");
            NewDt.Columns.Add("Conts");
            ShowTree(0);
            CX_Column_id.DataSource = NewDt.DefaultView;
            CX_Column_id.DataTextField = "Conts";
            CX_Column_id.DataValueField = "东东";
            CX_Column_id.DataBind();
        }
        catch
        { 
            
        }
        Chenge(CX_Column_id.SelectedValue);
    }
    int ii = 0;
    /// <summary>
    /// 返回菜单显示的HTML代码
    /// </summary>
    /// <param name="select">显示的展次</param>
    /// <returns></returns>
    public void ShowTree(int select)
    {
        string sql;
        int i = 0;
        DataTable MyDt = new DataTable();
        sql = "Select * From CX_Column where CX_Column_LX<>3 and CX_Column_followid =" + select + " order by CX_Column_id desc";
        try
        {

            MyDt = TextData.SqlataSet(sql).Tables[0];//创建DataTable MyDt
        }
        catch (Exception ex)
        {
            TextData.Err(ex.Message);

        }
        for (i = 0; i < MyDt.Rows.Count; i++)//遁环记录集
        {
            if (select == 0)//如果只一有层的话
            {

                DataRow Row = NewDt.NewRow();
                Row[0] = MyDt.Rows[i]["CX_Column_id"].ToString();
                Row[1] = TextData.EStr(ii, "…") + MyDt.Rows[i]["CX_Column_Name"].ToString();
                NewDt.Rows.Add(Row);

            }
            else
            {
                DataRow Row = NewDt.NewRow();
                Row[0] = MyDt.Rows[i]["CX_Column_id"].ToString();
                Row[1] = TextData.EStr(ii, "…") + MyDt.Rows[i]["CX_Column_Name"].ToString();
                NewDt.Rows.Add(Row);

            }
            ii = ii + 1;
            ShowTree(int.Parse(MyDt.Rows[i]["CX_Column_id"].ToString()));//调用自己显示菜单ＨＴＭＬ
            ii -= 1;

        }


    }

    /// <summary>
    /// 保存
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Button1_Click(object sender, EventArgs e)
    {
        PageSave();
    }
}
